package com.example.project.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.example.project.entity.IssueCategorie;

/**
 * 问题分类，定义项目中的问题分类Mapper接口
 * 
 * @author ruoyi
 * @date 2025-09-19
 */
@Mapper
public interface IssueCategorieMapper {

	/**
	 * 查询问题分类，定义项目中的问题分类
	 * 
	 * @param id 问题分类，定义项目中的问题分类主键
	 * @return 问题分类，定义项目中的问题分类
	 */
	@Select("select id, project_id, name from t_issue_categorie where del_flag = 0 and id = #{id}")
	public IssueCategorie selectIssueCategorieById(Long id);

	/**
	 * 查询问题分类，定义项目中的问题分类列表
	 * 
	 * @param tIssueCategories 问题分类，定义项目中的问题分类
	 * @return 问题分类，定义项目中的问题分类集合
	 */
	@Select({ "<script>", "select id, project_id, name from t_issue_categorie where del_flag = 0 ",
			"<if test=\"projectId != null\"> and project_id = #{projectId}</if>",
			"<if test=\"name != null and name != ''\"> and name like concat('%', #{name}, '%')</if>", "</script>" })
	public List<IssueCategorie> selectIssueCategorieList(IssueCategorie tIssueCategories);

	/**
	 * 新增问题分类，定义项目中的问题分类
	 * 
	 * @param tIssueCategories 问题分类，定义项目中的问题分类
	 * @return 结果
	 */
	@Insert({ "<script>", "insert into t_issue_categorie", "<trim prefix=\"(\" suffix=\")\" suffixOverrides=\",\">",
			"<if test=\"projectId != null\">project_id,</if>", "<if test=\"name != null and name != ''\">name,</if>",
			"</trim>", "<trim prefix=\"values (\" suffix=\")\" suffixOverrides=\",\">",
			"<if test=\"projectId != null\">#{projectId},</if>",
			"<if test=\"name != null and name != ''\">#{name},</if>", "</trim>", "</script>" })
	public int insertIssueCategorie(IssueCategorie tIssueCategories);

	/**
	 * 修改问题分类，定义项目中的问题分类
	 * 
	 * @param tIssueCategories 问题分类，定义项目中的问题分类
	 * @return 结果
	 */
	@Update({ "<script>", "update t_issue_categorie", "<trim prefix=\"SET\" suffixOverrides=\",\">",
			"<if test=\"projectId != null\">project_id = #{projectId},</if>",
			"<if test=\"name != null and name != ''\">name = #{name},</if>", "</trim>", "where id = #{id}",
			"</script>" })
	public int updateIssueCategorie(IssueCategorie tIssueCategories);

	/**
	 * 删除问题分类，定义项目中的问题分类
	 * 
	 * @param id 问题分类，定义项目中的问题分类主键
	 * @return 结果
	 */
//	@Delete("delete from t_issue_categorie where id = #{id}")
	@Update("update t_issue_categorie set del_flag = 1, update_time = NOW() where id = #{id}")
	public int deleteIssueCategorieById(Long id);

	/**
	 * 批量删除问题分类，定义项目中的问题分类
	 * 
	 * @param ids 需要删除的数据主键集合
	 * @return 结果
	 */
//	@Delete({ "<script>", "delete from t_issue_categorie where id in",
//			"<foreach item=\"id\" collection=\"array\" open=\"(\" separator=\",\" close=\")\">", "#{id}", "</foreach>",
//			"</script>" })
	@Update("<script>" + "update t_issue_categorie set del_flag = 1, update_time = NOW() where id in "
			+ "<foreach item='id' collection='array' open='(' separator=',' close=')'>" + "#{id}" + "</foreach>"
			+ "</script>")
	public int deleteIssueCategorieByIds(String[] ids);

	@Select("select id, project_id, name from t_issue_categorie where del_flag = 0")
	public List<IssueCategorie> selectIssueCategoriesAll();

	/**
	 * 根据项目ID和分类名称查询问题分类
	 * 
	 * @param projectId 项目ID
	 * @param name 分类名称
	 * @return 问题分类
	 */
	@Select("select id, project_id, name from t_issue_categorie where del_flag = 0 and project_id = #{projectId} and name = #{name}")
	public IssueCategorie selectIssueCategorieByProjectIdAndName(Long projectId, String name);
}
